package com.liao.controller;

import com.liao.bean.ServerCount;
import com.liao.bean.VisitList;
import com.liao.bean.result.Code;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.bean.result.Result;
import com.liao.service.ServerCountService;
import com.liao.service.VisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/visit")
public class VisitController {

    /**
     * 分页模糊查询客户业绩表
     */
    @Autowired
    private VisitService visitService;

    @ResponseBody
    @RequestMapping("/queryVisitListByPage")
    public PageResult<VisitList> queryVisitListByPage(Integer currentPage, Integer pageSize, String logId) throws Exception {

      PageResult<VisitList> pageResult=  visitService.queryVisitListByPage(currentPage,pageSize,logId);

      return pageResult;
    }

    /**
     * 删除
     * @param logId
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteVisitById")
    public Result deleteVisitById(Integer logId) throws Exception {

        visitService.deleteVisitById(logId);
        return new Result(true, Code.SERVERDEL_SUCCESS, Msg.SERVERDEL_SUCCESS,null);
    }

    /**
     * 批量删除
     * @param logIds
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteVisitByIdS")
    public Result deleteVisitByIdS(@RequestParam("logIds[]")List<Integer> logIds) throws Exception {

        for (Integer logId : logIds) {
            visitService.deleteVisitById(logId);
        }

        return new Result(true, Code.SERVER_DEL, Msg.SERVER_DEL,null);
    }

    /**
     * 添加
     * @param logId
     * @param goodId
     * @param visitIp
     * @param visitNum
     * @return
     */
    @ResponseBody
    @RequestMapping("/addVisit")
    public Result addVisit(Integer logId,String goodId,String visitIp,Integer visitNum) throws Exception {

        visitService.addVisit(logId,goodId,visitIp,visitNum);

        return new Result(true, Code.SERVER_ADD, Msg.SERVER_ADD,null);
    }

    /**
     * 根据scid修改用户
     * @param logId
     * @param goodId
     * @param visitIp
     * @param visitNum
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateVisit")
    public Result updateVisit(Integer logId,String goodId,String visitIp,Integer visitNum) throws Exception {
        visitService.updateVisit(logId,goodId,visitIp,visitNum);
        return new Result(true, Code.SERVER_UPDATE, Msg.SERVER_UPDATE,null);
    }
}
